package com.jiaai.cloud.system.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.base.page.CustomPage;
import com.jiaai.cloud.base.util.RestResultGenerator;
import com.baomidou.mybatisplus.plugins.Page;
import com.jiaai.cloud.system.entity.TLiveServerSearch;
import com.jiaai.cloud.system.service.ITLiveServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 * @title  ${}
 * @author 佳爱网络科技
 * @version V1.0
 * @since 2017-8-21
 */
@RestController
@RequestMapping("/api/manage/liveServer")
public class TLiveServerController {
    @Autowired
    private ITLiveServerService itLiveServerService;


    //查所有带分页
    @RequestMapping(value ="/findByAll",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    public Object findByAll(TLiveServerSearch search) throws ServiceException {
        try {
            Page page=search.getPagePlus();
            EntityWrapper wrapper=new EntityWrapper();
            itLiveServerService.selectPage(page,wrapper);
            return RestResultGenerator.genSuccessResult(new CustomPage(page));
        } catch (Exception e) {
            throw new ServiceException("查询失败", e.getMessage());
        }
    }

//    删除
    @RequestMapping(value = "/deleteId/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public Object deleteId(@PathVariable("id") Integer id) throws ServiceException {
        try {
            itLiveServerService.deleteById(id);
            return RestResultGenerator.genSuccessResult();
        } catch (Exception e) {
            throw new ServiceException("删除失敗", e.getMessage());
        }
    }

}
